//用户登录信息
var userInfo = new UserInfo();

function UserInfo() {
	var saveName = "$user";
	var _self = this;

	this.saveInfo = function(info) {
		localStorage.setItem(saveName, JSON.stringify(info));
	};

	//获取保存的登录信息
	this.getInfo = function() {
		var str = localStorage.getItem(saveName) || "";
		var strJ = "";
		if(str) {
			try {
				strJ = JSON.parse(str);
			} catch(e) {
				huiJsonLog("解析登录信息错误");
			};
		}
		return strJ;
	};

	//是否登录
	this.isLogin = function() {
		if(loginInfo = null) {
			this.getInfo();
		}

		if(typeof(loginInfo) != "undefined" && loginInfo != null) {
			return true;
		}

		return false;
	};
	
	
	//获取userid
	this.getUserid = function() {
		var str = this.getInfo();
		//}
		var id = "";
		if(str && str.userid) {
			id = str.userid ? str.userid : "";
		}
		return id;
	};

	//获取staffId
	this.getStaffId = function() {
		var str = this.getInfo();
		//}
		var id = "";
		if(str && str.staffID) {
			id = str.staffID ? str.staffID : "";
		}
		return id;
	};
	
	//获取loginID
	this.getLoginId = function() {
		var str = this.getInfo();
		//}
		var id = "";
		if(str && str.loginID) {
			id = str.loginID ? str.loginID : "";
		}
		return id;
	};
	
	//获取用户姓名
	this.getStaffName = function(){
		var str = this.getInfo();
		//}
		var id = "";
		if(str && str.staffName) {
			id = str.staffName ? str.staffName : "";
		}
		return id;
	}
	
}

//打开用户登录页面,登录后跳转
function loginWithRedirect(web) {
	window.localStorage.setItem("redirect", web);
	hui.open("login.html", {}, true, {});
}

//打开需要校验用户的网页
function openHtmlWithLogin(html) {
	if(IsNull(userInfo.getUserId())) {
		loginWithRedirect(html);
	} else {
		hui.open(html, {}, true, {});
	}
}